<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>creatRef</title>
</head>
<body>
  <div id="test"></div>

  <!-- 引入库：先引入核心库，再引入操作DOM的扩展库 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <!-- 将jsx转为js -->
  <script type="text/javascript" src="../js/babel.min.js"></script>
  <script type="text/babel">    //必须写babel，因为默认js
    class Demo extends React.Component{
      /*
        React.creatRef调用后可以返回一个容器，该容器可以存储被ref所标识的节点
        注意：一个容器仅仅存储一个节点
      */
      myRef = React.createRef()
      myRef2 = React.createRef()

      showData = ()=>{
        alert(this.myRef.current.value)
      }
      showData2 = ()=>{
        alert(this.myRef2.current.value)
      }

      render(){
        return (
          <div>
            <input ref={this.myRef} type="text" placeholder='点击按钮提示数据'/>
            <button onClick={this.showData}>点击提示left数据</button><br/>
            <input ref={this.myRef2} onBlur={this.showData2} type="text" placeholder='失去焦点提示数据'/>
          </div>
        )
      }
    }

    ReactDOM.render(<Demo/>, document.getElementById('test'))
  </script>
</body>
</html>